package containersvc

import (
	corev1 "gluenet/internal/agent/api/core/v1"
)

func (svc *Service) UpdateContainer(container *corev1.DockerContainer) corev1.CommonResp {
	obj, err := svc.objects.Get(container.GluenetGuid, container.GluenetKind)
	contianerObj, ok := obj.(*corev1.DockerContainerObj)

	if err != nil && !ok {
		goto ErrProcess
	}

	if err = svc.dd.Update(contianerObj.Spec.ID, container.Options); err != nil {
		goto ErrProcess
	}

	if contianerObj.Spec, err = svc.dd.Get(contianerObj.Spec.ID); err != nil {
		goto ErrProcess
	}

	return corev1.NewCommonSuccessRespWithData(contianerObj)

ErrProcess:
	svc.logger.Errorf(err.Error())
	return corev1.NewCommonFailureResp(err.Error())
}
